/*
    18. Write a C program to sort a list of elements using the insertionsort algorithm. 
    Input numbers you want to input: Input 5 values to sort

    The ascending order of the values:
    11
    13
    15
    20
    25
*/

#include <stdio.h>

int swap(int *a, int *b){
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void insertSort(int a[], int len){
    int i, j;
    for(i = 1; i < len; i++){
        for(j = i; j > 0; j--){
            if(a[j] < a[j - 1]){
                swap(&a[j], &a[j - 1]);
            }
        }
    }
}

void printArray(int a[], int len){
    int i;
    for(i = 0; i < len; i++){
        printf("%d, ", a[i]);
    }
    printf("\n");
}

int main(void)
{
    int a[5];
    int i;
    printf("Input numbers you want to input: Input 5 values to sort\n");
    for(i = 0; i < 5; i++){
        scanf("%d", &a[i]);
    }    
    insertSort(a, 5);
    printArray(a, 5);

    return 0;
}